/**
 * 
 */
package com.taobao.snowsnow.hibernate.dao.impl;

import java.util.List;

import org.hibernate.Query;

import com.taobao.snowsnow.hibernate.dao.ItemCollectDao;
import com.taobao.snowsnow.hibernate.pojo.ItemCollect;

/**
 * @author Tux
 *
 * 创建时间: 2011-4-29 上午09:45:11
 */
@SuppressWarnings("unchecked")
public class ItemCollectDaoImpl extends BaseDaoImpl implements ItemCollectDao {
	
	public ItemCollect findById(int id) throws Exception {
		return (ItemCollect) getHibernateTemplate().get(ItemCollect.class, id);
	}
	
	public List<ItemCollect> findByName(String name) throws Exception {
		return super.findByProperty(ItemCollect.class, "name", name);
	}

	public List<ItemCollect> findAll() throws Exception {
		return getHibernateTemplate().find("from ItemCollect");
	}

	public long getTotal() throws Exception {
		return super.countByCriteria(ItemCollect.class);
	}

	public List<ItemCollect> paging(int page, int limit) throws Exception {
		return super.findByCriteriaByPage(ItemCollect.class, page, limit);
	}

	@Override
	public ItemCollect getFirstObject() throws Exception {
		Query query = getSession().createQuery("from ItemCollect as c where c.id = (select min(id) from ItemCollect)");
		List<ItemCollect> list = query.list();
		if(list.size() !=0)
			return (ItemCollect) list.get(0);
		else return null;
	}

	@Override
	public ItemCollect getLastObject() throws Exception {
		Query query = getSession().createQuery("from ItemCollect as c where c.id = (select max(id) from ItemCollect)");
		List<ItemCollect> list = query.list();
		if(list.size() !=0)
			return (ItemCollect) list.get(0);
		else return null;
	}
}
